package API.Class.Math.GetFactorPro;

import java.util.Random;

public class EqulsNumber implements Runnable {
    public int t = 0;
    //临时比较缓存
    public long[] cacheEquals;

    public int a = 0;

    //运行成功返回true；否则返回false
    public boolean Equals() {
        int a = TwoThread.TwoThread.Get().times;
        Thread t1 = new Thread(this, "third");
        Thread t2 = new Thread(this, "forth");
        Random r = new Random(2);
        this.a--;
//        a--;
        while (a > 0) {
            if (r.nextInt(2) == 1) {
                t1.run();
            } else {
                t2.run();
            }
            a--;
        }
        return true;

    }

    @Override
    public void run() {
        if (t == 0)
            cacheEquals = resold2(TwoThread.TwoThread.Get().result1[a], TwoThread.TwoThread.Get().result1[--a]);
        else if (a > 0)
            cacheEquals = resold2(TwoThread.TwoThread.Get().result1[--a], cacheEquals);
        t++;
    }

    long[] resold2(long[] a, long[] b) {
        String cache = "";
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < b.length; j++) {
                if (a[i] == b[j]) {
                    cache += b[j] + "|";
                }
            }
        }
        StringBuilder str1 = new StringBuilder(cache);
        int len = str1.length() - 1;
        str1 = str1.deleteCharAt(len);
        return StringTolong.Cast(str1.toString());
    }
}
